home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d16 / nodee1a.arc / SOURCE.ARC / CLASSWIN.CPP next >
Text File  |  1991-09-20  |  3KB  |  128 lines

  1. /*
  2.  
  3.     CLASSWIN.CPP
  4.  
  5.             Copyright (c) 1991 by Borland International
  6.             All Rights Reserved.
  7.  
  8.  
  9.  
  10. */
  11.  
  12.     #ifndef __WINDOWS_H
  13.         #include <Windows.h>
  14.     #endif
  15.  
  16.     #ifndef __ASSERT_H
  17.         #include <assert.h>
  18.     #endif
  19.  
  20.     #ifndef __CLASSWIN_H
  21.         #include "ClassWin.h"
  22.     #endif
  23.  
  24. /* initialize static data members of class WinBase.*/
  25.  
  26.     HANDLE WinBase::hInst = 0;
  27.     HANDLE WinBase::hPrevInst = 0;
  28.     LPSTR WinBase::cmd = " ";
  29.     int WinBase::show = 0;
  30.  
  31.  
  32. /* members and data for class ModalDialog */
  33.  
  34.  
  35.  
  36.     ModalDialog *ModalDialog::curDlg = 0;
  37.  
  38.     WORD ModalDialog::run()
  39.     {
  40.         FARPROC dlgProc =
  41.                 MakeProcInstance( (FARPROC)ModalDialog::dlgProc, hInst );
  42.         DialogBox( hInst, getDialogName(), hWnd(), dlgProc );
  43.         FreeProcInstance( dlgProc );
  44.         return result;
  45.     }
  46.  
  47.     BOOL FAR PASCAL _export ModalDialog::dlgProc
  48.         ( HWND hDlg,WORD msg,    WORD wParam,LONG lParam    )
  49.     {
  50.         return curDlg->dispatch( hDlg, msg, wParam, lParam );
  51.     }
  52.  
  53.     BOOL ModalDialog::dispatch( HWND, WORD, WORD, LONG )
  54.     {
  55.         return FALSE;
  56.     }
  57.  
  58.  
  59. /*    members and data for class Window */
  60.  
  61.     Window *Window::inCreate = 0;
  62.     Window *Window::winList = 0;
  63.  
  64.     BOOL Window::create()
  65.     {
  66.         if( hPrevInst == 0 && registerClass() == FALSE )
  67.         {
  68.             return FALSE;
  69.         }
  70.  
  71.         inCreate = this;            // flag that we're inside CreateWindow()
  72.  
  73.         createWindow();
  74.  
  75.         nextWin = winList;          // insert this object into the Window list
  76.         winList = this;
  77.  
  78.         inCreate = 0;               // now it's OK to use normal dispatching
  79.  
  80.         return TRUE;
  81.     }
  82.  
  83.     WORD Window::run()
  84.     {
  85.         assert( hWnd() != 0 );      // check that we really exist
  86.  
  87.         MSG msg;
  88.         while( GetMessage( &msg, NULL, NULL, NULL ) != 0 )
  89.         {
  90.             TranslateMessage( &msg );
  91.             DispatchMessage( &msg );
  92.         }
  93.         return msg.wParam;
  94.     }
  95.  
  96.     LONG Window::dispatch( WORD msg, WORD wParam, long lParam )
  97.     {
  98.         return DefWindowProc( hWnd(), msg, wParam, lParam );
  99.     }
  100.  
  101.     LONG FAR PASCAL Window::wndProc
  102.         ( HWND hWnd, WORD msg, WORD wParam, long lParam )
  103.     {
  104.  
  105.         Window *cur = Window::winList;
  106.  
  107.         //  look up the handle in our Window list
  108.         while( cur != 0 && cur->hWnd() != hWnd )
  109.                 cur = cur->nextWin;
  110.  
  111.         //  normal dispatching
  112.         if( cur != 0 )
  113.                 return cur->dispatch( msg, wParam, lParam );
  114.  
  115.         //  if we're inside CreateWindow(), assume that the message is for us
  116.         if( inCreate != 0 )
  117.                 {
  118.                 inCreate->hWindow = hWnd;
  119.                 return inCreate->dispatch( msg, wParam, lParam );
  120.                 }
  121.  
  122.         //  otherwise, pass it on to windows
  123.         return DefWindowProc( hWnd, msg, wParam, lParam );
  124.     }
  125.  
  126.  
  127.  
  128.